package cn.schoolwow.workflow.test.module.oa.common.flow.node;

import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import cn.schoolwow.workflow.domain.deploy.WorkFlowDeployFileContext;
import cn.schoolwow.workflow.domain.deploy.WorkFlowDeployNode;
import cn.schoolwow.workflow.test.module.oa.common.flow.common.ConvertDeployAssignerTypeAndAddAssignerCommonFlow;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

public class ConvertCarbonCopyNodeCommonFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        JSONObject childNode = flowContext.checkData("childNode", JSONObject.class);
        WorkFlowDeployNode workFlowDeployNode = flowContext.checkInstanceData(WorkFlowDeployNode.class);
        WorkFlowDeployFileContext workFlowDeployFileContext = flowContext.checkInstanceData(WorkFlowDeployFileContext.class);

        JSONArray ccs = childNode.getJSONArray("ccs");
        flowContext.startFlow(new ConvertDeployAssignerTypeAndAddAssignerCommonFlow())
                .putCurrentCompositeFlowData("array", ccs)
                .putCurrentCompositeFlowData("fieldName", "ccType")
                .putCurrentCompositeFlowInstanceData(workFlowDeployNode)
                .execute();
        workFlowDeployFileContext.nodes.add(workFlowDeployNode);
    }

    @Override
    public String name() {
        return "转换抄送节点公共流程";
    }
}
